package com.xxzuibang.day11.房屋出租系统项目.service;

import com.xxzuibang.day11.房屋出租系统项目.domain.House1;

public class HouseService1 {
    private House1[] house1s;
    private int houseNum=1;
    private int countId=1;

    public HouseService1(int size) {
        house1s=new House1[size];
        house1s[0]=new House1(0,"红红","123456","陕西",1000,"未出租");
    }
    public House1[] list(){
        return house1s;
    }

    public boolean add(House1 newHouse) {
        if(houseNum==house1s.length){
            System.out.println("数据已满，无法添加！");
        }
            house1s[houseNum]=newHouse;
            houseNum++;
            countId++;
            newHouse.setId(countId);
        return true;
    }

    public House1 findById(int findId) {
        for (int i = 0; i < houseNum; i++) {
            if(findId==house1s[i].getId()){
                return house1s[i];
            }
        }
        return null;
    }

    public boolean del(int delId) {
        int index=-1;
        for (int i = 0; i < houseNum; i++) {
            if(delId==house1s[i].getId()){
                index=i;
            }
        }
        if(index==-1){
            return false;
        }
        for(int i=index;i<houseNum-1;i++){
            house1s[i]=house1s[i+1];
        }
        house1s[houseNum-1]=null;
        houseNum--;
        return true;
    }
}
